package reno.alerts.dao;

import org.hibernate.Session;
import org.hibernate.query.NativeQuery;
import org.springframework.stereotype.Repository;
import reno.alerts.common.HibernateUtils;
import reno.alerts.entity.AlertsEO;
import reno.alerts.entity.StarsEO;
import reno.alerts.entity.TypesEO;

import java.util.List;

@Repository
public class AlertsDao {


    public List<AlertsEO> queryAlerts(String rewardOne) {
        String sql = "select * from alerts where en like 'TARGET'";
        Session session = HibernateUtils.getSession();
        NativeQuery<AlertsEO> query = session.createNativeQuery(sql.replace("TARGET", rewardOne.replace(" ", "%")),AlertsEO.class);
        List<AlertsEO> alertsEOList = query.getResultList();
        session.close();
        return alertsEOList;
    }

    public List<StarsEO> queryStars(String node) {
        String sql = "SELECT * FROM stars where en = 'TARGET'";
        Session session = HibernateUtils.getSession();
        NativeQuery<StarsEO> query = session.createNativeQuery(sql.replace("TARGET", node),StarsEO.class);
        List<StarsEO> starsEOList = query.getResultList();
        session.close();
        return starsEOList;
    }

    public List<TypesEO> queryType(String type) {
        String sql = "SELECT * FROM types where en = 'TARGET'";
        Session session = HibernateUtils.getSession();
        NativeQuery<TypesEO> query = session.createNativeQuery(sql.replace("TARGET", type),TypesEO.class);
        List<TypesEO> typesEOList = query.getResultList();
        session.close();
        return typesEOList;
    }
}
